﻿using System;
using System.Windows.Forms;

namespace LIK.WakeOnLan.Forms
{
    public partial class FormInputIp : DevExpress.XtraEditors.XtraForm
    {
        public string IpAddress
        {
            get { return textEditIpAddress.Text; }
            set { textEditIpAddress.Text = value; }
        }

        public FormInputIp()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            this.dxErrorProvider.ClearErrors();
            this.ValidateChildren(ValidationConstraints.Enabled);
            if (this.dxErrorProvider.HasErrors)
            {
                this.DialogResult = DialogResult.None;
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void textEditIpAddress_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            string strIpAddress = textEditIpAddress.Text;
            if (string.IsNullOrEmpty(strIpAddress))
            {
                goto err;
            }
            string[] ipData = strIpAddress.Split('.');
            if (ipData.Length != 4)
            {
                goto err;
            }
            foreach (string subIpAddress in ipData)
            {
                if (string.IsNullOrEmpty(subIpAddress))
                {
                    goto err;
                }
            }
            return;
            err:
            this.dxErrorProvider.SetError(textEditIpAddress, "Enter valid IP address");
        }
    }
}